﻿
#pragma once

#define COLOR_BITDEPTH				16
#define COLOR_RMASK					0xf800
#define COLOR_GMASK					0x07e0
#define COLOR_BMASK					0x001f

#define COLOR_RVALUE(c)				(((c) & COLOR_RMASK) >> 11)
#define COLOR_GVALUE(c)				(((c) & COLOR_GMASK) >> 5)
#define COLOR_BVALUE(c)				((c) & COLOR_BMASK)
#define COLOR_RMAX					31
#define COLOR_GMAX					63
#define COLOR_BMAX					31
#define COLOR_AMAX					255
#define COLOR_MAKECOLOR(r, g, b)	(WORD)((b) | ((INT)(g) << 5) | ((INT)(r) << 11))
#define COLOR_MAKERGB(r, g, b)		COLOR_MAKECOLOR((r) >> 3, (g) >> 2, (b) >> 3)

#define RGBA(r, g, b, a)			(COLORREF)(RGB(r, g, b) | (((INT)(a) & 0xff) << 24))
#define GetAValue(rgba)				(HIBYTE(HIWORD(rgba)))
#define RGB2RGBA(rgb, a)			((COLORREF)((rgb) & 0x00ffffff) | (((INT)(a) & 0xff) << 24))

enum COLOR_MODE
{
	CM_UNKNOWN,
	CM_R5G6B5,
	CM_A1R5G5B5,
	CM_R8B8G8,
	CM_G8R8B8,
	CM_A8R8G8B8,
	CM_A8B8G8R8,
	CM_TOTALNUM,
};

struct COLORMODE_TABLE
{
	INT bit_depth;
	INT max_red;
	INT max_green;
	INT max_blue;
	INT max_alpha;
	DWORD red_mask;
	DWORD green_mask;
	DWORD blue_mask;
	DWORD alpha_mask;
};

static const COLORMODE_TABLE CM_TABLE[] =
{
	// bit_depth	max_red		max_green	max_blue	max_alpha	red_mask	green_mask	blue_mask	alpha_mask
	{  0,			  0,		  0,		  0,		  0,		0x00000000,	0x00000000,	0x00000000,	0x00000000 },	// CM_UNKNOWN
	{ 16,			 31,		 63,		 31,		  0,		0x0000f800,	0x000007e0,	0x0000001f,	0x00000000 },	// CM_R5G6B5
	{ 16,			 31,		 31,		 31,		  1,		0x00007c00,	0x000003e0,	0x0000001f,	0x80000000 },	// CM_A1R5G5B5
	{ 24,			255,		255,		255,		  0,		0x00ff0000,	0x0000ff00,	0x000000ff,	0x00000000 },	// CM_R8G8B8
	{ 24,			255,		255,		255,		  0,		0x000000ff,	0x0000ff00,	0x00ff0000,	0x00000000 },	// CM_B8G8R8
	{ 32,			255,		255,		255,		255,		0x00ff0000,	0x0000ff00,	0x000000ff,	0xff000000 },	// CM_A8R8G8B8
	{ 32,			255,		255,		255,		255,		0x000000ff,	0x0000ff00,	0x00ff0000,	0xff000000 },	// CM_A8B8G8R8
};
